#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int a[n*2];
    for(int i=0;i<n*2;i++){
        scanf("%d",&a[i]);
    }
    int m;
    scanf("%d",&m);
    int b[m*2];
    for(int i=0;i<2*m;i++){
        scanf("%d",&b[i]);
    }
    for(int i=0;i<m*2;i+=2){
        for(int j=0;j<n*2;j+=2){
            if(i==4 && j==6){
                printf("%d ",a[j]*b[i]);
                printf("%d",a[j+1]+b[i+1]);
            }
            else{
                printf("%d ",a[j]*b[i]);
                printf("%d ",a[j+1]+b[i+1]);
            }
        }
    }
    for(int i=0;i<n*2;i+=2){
        for(int j=0;j<m*2;j+=2){
            if(a[i+1]>b[i+1]){
                printf("%d %d ",a[i],a[i+1]);
            }else if(a[i+1]<b[i+1]){
                printf("%d %d ",b[i],b[i+1]);
            }else{
                printf("%d %d ",a[i]+b[i],a[i+1]);
            }
        }
    }
}